// 
//  Copyright (C) 2004-2009  Autodesk, Inc.
//  
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of version 2.1 of the GNU Lesser
//  General Public License as published by the Free Software Foundation.
//  
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//  
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#ifndef MAPINFOFEATUREREADER_H_
#define MAPINFOFEATUREREADER_H_

#include "FdoDefaultFeatureReader.h"

class FdoExpressionEngine;
class FdoExpressionEngineFunctionCollection;

class MapInfoFeatureReader : public FdoDefaultFeatureReader
{
public:
    MAPINFO_API MapInfoFeatureReader(MapInfoConnection* connection,
                             MapInfoClassDefinition* mapinfoClassDef,
                             FdoIdentifierCollection* selectedProps,
                             recno_list * features = NULL);

protected:
    MAPINFO_API virtual ~MapInfoFeatureReader();

//-------------------------------------------------------
// FdoIDisposable implementation
//-------------------------------------------------------

protected:
// dispose this object
    MAPINFO_API virtual void Dispose();

//-------------------------------------------------------
// FdoIFeatureReader implementation
//-------------------------------------------------------

public:
    MAPINFO_API virtual FdoClassDefinition* GetClassDefinition();
    MAPINFO_API virtual FdoInt32 GetDepth();
    MAPINFO_API virtual bool GetBoolean(FdoString* propertyName);
    MAPINFO_API virtual FdoByte GetByte(FdoString* propertyName);
    MAPINFO_API virtual FdoDateTime GetDateTime(FdoString* propertyName);
    MAPINFO_API virtual double GetDouble(FdoString* propertyName);
    MAPINFO_API virtual FdoInt16 GetInt16(FdoString* propertyName);
    MAPINFO_API virtual FdoInt32 GetInt32(FdoString* propertyName);
    MAPINFO_API virtual FdoInt64 GetInt64(FdoString* propertyName);
    MAPINFO_API virtual float GetSingle(FdoString* propertyName);
    MAPINFO_API virtual FdoString* GetString(FdoString* propertyName);
    MAPINFO_API virtual FdoLOBValue* GetLOB(FdoString* propertyName);
    MAPINFO_API virtual FdoIStreamReader* GetLOBStreamReader(FdoString* propertyName );
    MAPINFO_API virtual bool IsNull(FdoString* propertyName);
    MAPINFO_API virtual FdoIFeatureReader* GetFeatureObject(FdoString* propertyName);
    MAPINFO_API virtual FdoByteArray* GetGeometry(FdoString* propertyName);
    MAPINFO_API virtual const FdoByte* GetGeometry(FdoString* propertyName, FdoInt32* len);
    MAPINFO_API virtual FdoIRaster* GetRaster(FdoString* propertyName);
    MAPINFO_API virtual bool ReadNext();
    MAPINFO_API virtual void Close();
    virtual FdoDataType GetDataType( FdoString* propertyName ); 

private:

    void CheckIfPropExists(FdoString* propertyName);
    virtual const FdoByte* GetGeometry(OGRGeometry* geom, FdoInt32* len);

    MapInfoConnection* m_connection;
    FdoClassDefinition* m_class;
    FdoStringP m_idPropName;
    FdoStringP m_geomPropName;
    FdoIdentifierCollection * m_selectedProps;

    IMapInfoFile* m_poLayer;
    FdoExpressionEngine *m_filterExec;

    TABFeature* m_poFeature;
    FdoSpatialOperations m_spatialOperation;

    std::map<long, std::wstring> m_sprops;
    std::map<std::wstring, FdoDataType> m_propDataTypeMap;
    
    unsigned char* m_fgf;
    unsigned char* m_wkb;
    size_t m_fgflen;

    recno_list * m_pFeatures;
    long m_nCurrentFeature;
};

#endif

